<template>
  <div className="app-container">
    <div className="table-container">
      <base-list
        ref="table"
        url="/user_setting"
        :options="options"
        :columns="columns"
        :format="format"
        :rules="rules"
        permission="ADMIN"
        @reloadOptions="handleGetOptions"
      />
    </div>
  </div>
</template>

<script>
import {getBaseList, getBaseOptions} from '@/api/common'
import BaseList from '@/components/BaseList/index.vue'

export default {
  name: 'UserSetting',
  components: {BaseList},
  data() {
    return {
      columns: [
        {show: true, edit: false, width: '100', key: 'id', fixed: true, label: 'ID', tooltip: 'ID', type: 'NUMBER', queryable: true, sortable: true},
        {show: true, edit: true, width: 'auto',minWidth: '300', key: 'user', label: '用户', tooltip: '用户', type: 'REMOTE_SELECT', remote: {url: '/user_info', label: 'nickName',multiple: false}, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'bookPublic', label: '公开书房', tooltip: '公开书房', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'territoryPublic', label: '公开领域', tooltip: '公开领域', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'planPublic', label: '公开计划', tooltip: '公开计划', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},

        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'fansPublic', label: '公开粉丝', tooltip: '公开粉丝', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'attentionPublic', label: '公开关注', tooltip: '公开关注', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'likePublic', label: '公开喜欢', tooltip: '公开喜欢', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},
        {show: true, edit: true, width: 'auto',minWidth: '100', key: 'favoritePublic', label: '公开收藏', tooltip: '公开收藏', type: 'DICTIONARY', optionKey: 'publicOptions', sortable: true, queryable: true},


        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createTime', label: '创建时间', tooltip: '创建时间', type: 'DATE_TIME'},
        {show: true, edit: false, width: 'auto',minWidth: '200', key: 'updateTime', label: '更新时间', tooltip: '更新时间', type: 'DATE_TIME', queryable: true},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'createUser', label: '创建人', tooltip: '创建人', type: 'WORD'},
        {show: false, edit: false, width: 'auto',minWidth: '200', key: 'updateUser', label: '修改人', tooltip: '修改人', type: 'WORD'},
      ],
      format: {
        user: (data, index) => {
          return data.user ? data.user.nickName + '('+data.user.id+')' : ''
        },
        createUser: (data, index) => {
          return data.createUser ? data.createUser.nickName + '('+data.createUser.id+')' : ''
        },
        updateUser: (data, index) => {
          return data.updateUser ? data.updateUser.nickName + '('+data.updateUser.id+')' : ''
        }
      },
      rules: {
        add: {
          bookPublic: [{required: true, message: 'bookPublic必填!', trigger: 'blur'}],
          territoryPublic: [{required: true, message: 'territoryPublic必填!', trigger: 'blur'}],
          planPublic: [{required: true, message: 'planPublic必填!', trigger: 'blur'}],

        },
        edit: {
          id: [{required: true, message: '请选择数据!', trigger: 'change'}],
          bookPublic: [{required: true, message: 'bookPublic必填!', trigger: 'blur'}],
          territoryPublic: [{required: true, message: 'territoryPublic必填!', trigger: 'blur'}],
          planPublic: [{required: true, message: 'planPublic必填!', trigger: 'blur'}],

        }
      },
      options: {
        publicOptions: [
          {id: 'PUBLIC', name: '公开', type: 'success'},
          {id: 'FANS', name: '对粉丝开放', type: 'primary'},
          {id: 'FRIEND', name: '对朋友开放', type: 'warning'},
          {id: 'PRIVATE', name: '不公开', type: 'danger'}
        ]
      }
    }
  },

  created() {
    this.handleGetOptions()
  },
  mounted() {
  },
  methods: {
    handleGetOptions() {
      const options = JSON.parse(localStorage.getItem('allOptions'))
      if (options) {
        this.options = Object.assign(this.options, options)
      }
    }
  }
}
</script>


